<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台主页模块 - XzcBlogTemplate后台管理</title>
    <link rel="stylesheet" href="static/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="static/admin/css/common.css">
    <link rel="stylesheet" type="text/css" href="static/admin/css/blogadd.css">
    <link rel="stylesheet" href="static/admin/css/main.css">
</head>
<body>
<div class="layui-container main">
    <div class="layui-row layui-col-space20">
        <div class="layui-col-md12">
            <p>
		        	<span class="layui-breadcrumb" style="visibility: visible;">
<!--			          	<a href="./main.html">博客管理系统</a><span lay-separator="">/</span>-->
			          	<a >博客管理系统</a><span lay-separator="">/</span>
<!--			          	<a href="./main.html">后台首页</a><span lay-separator="">/</span>-->
			          	<a >后台首页</a><span lay-separator="">/</span>
<!--			          	<a><cite>文章管理</cite></a>-->
			          	<a>文章管理</a>
		        	</span>
            </p>
        </div>
        <div class="layui-col-md12">
            <table class="layui-table">
                <colgroup>
                    <col width="200">
                    <col width="400">
                    <col>
                </colgroup>
                <thead>
                <tr>
                    <th>标题</th>
                    <th>内容简介</th>
                    <th>分类/标签</th>

                    <th>是否置顶</th>
                    <th>查看数</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td id="a1"></td>
                    <td id="a2">

                    </td>
                    <td>闲言碎语</td>
                    <td id="a3"></td>
                    <td id="a4"><input type="checkbox" name="zzz" lay-skin="switch" lay-text="开启|关闭"></td>
                    <td id="a5"></td>
                    <td id="a6"></td>
                    <td>
                        <a href="blogupdate.html" class="layui-btn layui-btn-normal">编辑</a>
                        <a id="del_btn" href="javascript:;" class="layui-btn layui-btn-danger">删除</a>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="layui-col-md12" id="pages">
                1111
            </div>
        </div>

    </div>


</div>

<input type="hidden" name="uid">
</body>
<script src="static/js/jquery-1.12.4.min.js"></script>
<script src="static/layui/layui.all.js"></script>
<script>
    $(function () {
        $("#del_btn").click(function () {
            layer.confirm("数据已经发生改变是否确认修改？", {
                btn: ["确定", "取消"] //按钮
            }, function (index) {
                alert('点击了确认的回调函数');
                layer.close(index);
            }, function () {
                alert('点击了取消的回调函数');
                layer.close();
            });
        });
    });

    $(document).ready(function () {
        var uid = sessionStorage.getItem('uid');
        var identity = sessionStorage.getItem('identity');
        // alert("identity1:"+identity);
        if (identity==1){
            // alert("进入管理员功能界面！")
            $.get("blog/showAll", {
            }, function (rs) {
                // indexPage=rs.page.indexPage;//玉泽思路添加数据
                forblog(rs);//进入后台页面显示登录账号对应的数据
                // showPage(rs);
            });
        }else {
            $.get("blog/findByUid", {
                "uid": uid
            }, function (rs) {
                // indexPage=rs.page.indexPage;//玉泽思路添加数据
                forblog(rs);//进入后台页面显示登录账号对应的数据
                // showPage(rs);
            });
        }
    });

    //分页设定开始标记
    //1显示分页的样式
    function showPage(rs) {
        $("#pages").empty();
        var indexPage = rs.page.indexPage;
        var countPage = rs.page.countPage;

        $("<input type='button' style=\"visibility: visible;\" id='b1' value='上一页' name='" + (indexPage - 1) + "'/>").appendTo("#pages");
        for (var i = 1; i <= countPage; i++) {
            if (i == indexPage) {
                $("<input type='button' name='page' value='" + i + "' style='background-color: aqua' height='100px' width='100px'/>").appendTo("#pages");
            } else {
                $("<input type='button' name='page' value='" + i + "' style='background-color: gainsboro' height='100px' width='100px'/>").appendTo("#pages");
            }
        }
        $("<input type='button' style=\"visibility: visible;\" id='b1' class='" + (countPage + 1) + "' value='下一页' name='" + (indexPage + 1) + "'/>").appendTo("#pages");
    }

    //2分页中点击对应页数显示的数据
    $(document).on("click", "[name='page']", function () {
        var indexPage = $(this).val();
        var uid = sessionStorage.getItem('uid');
        var identity = sessionStorage.getItem('identity');
        // alert("identity2:"+identity);
        if(identity ==1){
            $.get("blog/showAll", {
                "indexPage": indexPage
            }, function (rs) {
                forblog(rs);
            });
        }else{
            $.get("blog/findByUid", {
                "indexPage": indexPage,
                "uid": uid
            }, function (rs) {
                forblog(rs);
            });
        }
    });

    //3分页中点击下一页或上一页所显示的数据
    $(document).on("click", "#b1", function () {
        var indexPage = $(this).attr("name");
        var countpage = $(this).attr("class");
        var uid = sessionStorage.getItem('uid');
        var identity = sessionStorage.getItem('identity');
        if (indexPage == 0) {
            alert("已是第一页");
        } else if (indexPage == countpage) {
            alert("已是最后一页");
        } else if (identity ==1){
            // alert("identity3:"+identity);
            $.get("blog/showAll", {
                "indexPage": indexPage
            }, function (rs) {
                forblog(rs);
            });
        }else {
            $.get("blog/findByUid", {
                "indexPage": indexPage,
                "uid": uid
            }, function (rs) {
                forblog(rs);
            });
        }
    });

    //分页结束标记

    function forblog(rs){
        $("tbody").empty();
        var wos = rs.result;
        for (var i = 0; i < wos.length; i++) {
            $("<tr>\n" +
                "        <td id='a1'>" + wos[i].title + "</td>\n" +
                "        <td id='a2'>" + wos[i].detail + "</td>\n" +
                "        <td id='a3'>" + wos[i].typeName + "</td>\n" +
                "        <td id='a4'>" + wos[i].status + "</td>\n" +
                "        <td id='a5'>" + wos[i].clicknumber + "</td>\n" +
                "        <td id='a6'>" + wos[i].posttime + "</td>\n" +
                "<td>\n" +
                "                        <a name='" + wos[i].blogid + "' id='update' href=\"blogupdate.html\" class=\"layui-btn layui-btn-normal\">编辑</a>\n" +
                // "                        <a name='" + wos[i].blogid + "' id=\"del_btn\" href=\"bloglist.html\" class=\"layui-btn layui-btn-danger\">删除</a>\n" +
                "                        <a name='" + wos[i].blogid + "' id=\"del_btn\" href=\"javascript:;\" class=\"layui-btn layui-btn-danger\">删除</a>\n" +
                "                    </td>" +
                "    </tr>").appendTo("tbody");
        }
        showPage(rs);//添加分页的数据和组件
    }

    //删除
    $(document).on("click", "#del_btn", function () {
        var blogid = $(this).attr("name");
        var uid = sessionStorage.getItem('uid');
        $.get("blog/deleteByBlogId", {
            "blogid": blogid,
            "uid": uid
        }, function (rs) {
            alert("删除成功")
            forblog(rs);
        });
    });
    //编辑
    $(document).on("click","#update",function () {
        var blogid = $(this).attr("name");
        sessionStorage.setItem('blogid',blogid);
    })

</script>
</html>